# 对称二叉搜索树


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right 

class Solution:

    def isSymmetric(self, root):
        def recur(L, R):
            if not L and not R:
                return True
            
            if not L or not R or L.val != R.val:
                return False
            
            return recur(L.left, R.right) and recur(L.right, R.left)
        
        return not root or recur(root.left, root.right)


def array_to_binary_tree(arr):
    if not arr:
        return None
    
    root = TreeNode(arr[0])
    queue = [root]
    i = 1

    while queue and i < len(arr):
        node = queue.pop(0)
        # 左子节点
        if i < len(arr):
            node.left = TreeNode(arr[i])
            queue.append(node.left)
            i += 1
        # 右子节点
        if i < len(arr):
            node.right = TreeNode(arr[i])
            queue.append(node.right)
            i += 1

        
    return root



if __name__ == "__main__":

    arr = [1,2,2,3,4,4,3]
    root = array_to_binary_tree(arr)

    sol = Solution()
    result = sol.isSymmetric(root)

    print(result)



